package org.academic.texteditor.gui.plugin.list;


import java.util.EventObject;

import javax.swing.JMenu;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;

import org.academic.texteditor.gui.component.menu.MenuFactory;
import org.academic.texteditor.gui.plugin.AbstractParagraphPlugin;
import org.edkits.gui.ComponentHandler;
import org.edkits.latex.LaTeXTags;

public class NumberingPlugin extends AbstractParagraphPlugin {

	private static final long serialVersionUID = 7714072401361873191L;
	
	public NumberingPlugin() {
		super("numberingPlugin");
	}

	@Override
	protected String getMenuItemKey() {
		return "menu.insert.numbering";
	}

	@Override
	protected String getMenuItemName() {
		return "numbering";
	}

	@Override
	protected JMenu getParentMenu() {
		return MenuFactory.getInsert();
	}
	
	@Override
	protected SimpleAttributeSet getOffAttributeSet() {
		return new SimpleAttributeSet();
	}

	@Override
	protected SimpleAttributeSet getOnAttributeSet() {
		SimpleAttributeSet attributeSet = getOffAttributeSet();
		attributeSet.addAttribute(LaTeXTags.STYLE_LIST, LaTeXTags.LIST_ENUM);
		attributeSet.removeAttribute(StyleConstants.Alignment);
		return attributeSet;
	}

	@Override
	protected ComponentHandler getComponentHandler() {
		ComponentHandler handler = new ComponentHandler() {
			@Override
			public boolean addingAttributes(EventObject obj) {
				return false;
			}
			@Override
			public Object getAttributeValue() {
				return null;
			}
			@Override
			public void handleComponent(int dot, boolean matching, Object value) {
				if (value == null || !value.equals(LaTeXTags.LIST_ENUM)) {
					menuItem.setSelected(false);
					return;
				}
				menuItem.setSelected(value.equals(getMenuItemName()));
			}
			@Override
			public boolean handlesThis(EventObject obj) {
				return false;
			}
		};
		return handler;
	}
	
}
